<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <button>显示与隐藏</button>
    <hr>
    <div id="box"></div>
    <script src="js/public.js">
    </script>
    <script>
        var btn = document.querySelector('button')
        var div = $('#box')
        var flag = true
        btn.onclick = function() {
            if (flag) {
                div.style.display = 'none'
                flag = false
            } else {
                div.style.display = 'block'
                flag = true
            }
        }
    </script>
</body>

</html>